<?php
/**
 * Created by PhpStorm.
 * User: 86188
 * Date: 2020/12/2
 * Time: 15:49
 */

namespace app\test\controller;


use think\Controller;
use app\service\apiService;
class User extends Controller
{
    public function index(){
        $redirect_uri="https://www.aliwgzf.com/test/user/getuser";
        $url="https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=2017100709184374&scope=auth_base,auth_invoice_info&redirect_uri=$redirect_uri";
        header("Location:".$url);
    }


    public function getuser(){

        $api = new apiService();
        //获取当前用户支付宝ID
        $code = request()->get('auth_code');
        $oauthtoken = $api->oauthToken($code);
        if(property_exists($oauthtoken,'sub_msg')){
            return json(['info' => $oauthtoken->sub_msg]);
        }

        $info["user_id"]=$oauthtoken->user_id;
        $info["auth_token"]=$oauthtoken->access_token;
        $rs=$api->getInvoiceTitleList(json_encode($info));
        echo "<pre>";
        var_dump($rs);
    }
}